load("@bazel_skylib//rules:write_file.bzl", "write_file")

_GIT2_FEATURES_H = """
#define GIT_REGEX_BUILTIN
#define GIT_SHA1_COLLISIONDETECT
#define GIT_SHA256_BUILTIN
#define GIT_IO_POLL
#define GIT_HTTPPARSER_BUILTIN
"""

write_file(
    name = "git2_features_h",
    out = "git2_features.h",
    content = [_GIT2_FEATURES_H],
    newline = "unix",
)

cc_library(
    name = "git2_features",
    hdrs = [":git2_features_h"],
    strip_include_prefix = "/src/util",
)

cc_library(
    name = "util_hdrs",
    hdrs = glob(["**/*.h"]),
    strip_include_prefix = "/src/util",
    visibility = ["//:__subpackages__"],
    deps = [
        ":git2_features",
        "//deps/pcre:pcre_hdrs",
        "//include:git2",
        "@zlib",
    ],
)

cc_library(
    name = "util",
    srcs = glob(
        include = ["**/*.c"],
        exclude = [
            "hash/common_crypto.c",
            "hash/openssl.c",
            "hash/win32.c",
            "win32/*",
        ],
    ),
    implementation_deps = [
        "//deps/pcre",
        "//deps/xdiff",
    ],
    visibility = ["//:__subpackages__"],
    deps = [":util_hdrs"],
)
